package com.lx.collection;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.function.Consumer;

public class collectiondemo {
    public static void main(String[] args) {
        //collection是借口，需要创建实现类的对象
        //collection单列集合的顶层接口
        Collection<String> coll = new ArrayList<>();
        coll.add("aaa");
        coll.add("bbb");
        coll.add("ccc");
        System.out.println(coll);
        System.out.println(coll.isEmpty());
        coll.remove("aaa");
        System.out.println(coll);
//        coll.clear();
        System.out.println(coll);
        Collection<Student> colt = new ArrayList<>();
        Student st1 = new Student("lisi",27);
        Student st2 = new Student("zhangsan",22);
        colt.add(st1);
        colt.add(st2);
        Student st3 = new Student("lisi",27);
        //比较的是地址值，因此返回的是false，若想返回true，需要重写equils方法
        System.out.println(colt.contains(st3));
        System.out.println("==============================");
        Iterator<String> it = coll.iterator();
        while(it.hasNext())
        {
            System.out.println(it.next());
        }
        //增强for
        for (String value : coll) {
            System.out.println(value);
        }
        //利用lambda表达式遍历
        coll.forEach(new Consumer<String>() {
            @Override
            public void accept(String s) {
                System.out.println(s);
            }
        });
        coll.forEach(s -> System.out.println(s));
    }
}
